package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.WaitingOrderBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.widget.StateButton;

import java.util.List;


public class NotTakeLetterAdapter extends ListBaseAdapter<WaitingOrderBean.ListBean> {


    public NotTakeLetterAdapter(Context context, List<WaitingOrderBean.ListBean> mDataList) {
        super(context, mDataList);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder,final int position) {
        TextView business=holder.getView(R.id.business);
        TextView orderNo=holder.getView(R.id.orderNo);
        TextView takeDate=holder.getView(R.id.takeDate);
        TextView takeName=holder.getView(R.id.takeName);
        TextView takePhone=holder.getView(R.id.takePhone);
        TextView takeAddress=holder.getView(R.id.takeAddress);
        TextView userRemark=holder.getView(R.id.userRemark);
        TextView modifyPrice=holder.getView(R.id.modifyPrice);
        TextView payablePrice=holder.getView(R.id.payablePrice);
        TextView payStatusText=holder.getView(R.id.payStatusText);
        LinearLayout modifyPriceLayout=holder.getView(R.id.modifyPrice_layout);
        LinearLayout payablePriceLayout=holder.getView(R.id.payablePrice_layout);
        StateButton priceBtn=holder.getView(R.id.price_btn);
        StateButton recordBtn=holder.getView(R.id.record_btn);
        LinearLayout takePhoneLayout=holder.getView(R.id.takePhone_layout);


        WaitingOrderBean.ListBean item = mDataList.get(position);
        String  takeTime=item.getTakeDate();
        String  takeTimeStart=item.getTakeTimeStart();
        String     takeTimeEnd=item.getTakeTimeEnd();
        payStatusText.setText(item.getPayStatusText());
        orderNo.setText(item.getOrderNo());
        takeDate.setText(!CheckUtils.isEmpty(takeTime) && !CheckUtils.isEmpty(takeTimeStart) ? takeTime + " " + takeTimeStart + "-" + takeTimeEnd : "");
        takePhone.setText(item.getTakePhone());
        takeName.setText(item.getTakeName());
        takeAddress.setText(item.getTakeAddress());
        userRemark.setText(item.getUserRemark());

      //  priceBtn.setVisibility(item.getPayStatus() ?View.GONE : View.VISIBLE);
        payStatusText.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        modifyPrice.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        payablePrice.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        if (!CheckUtils.isEmpty(item.getBusiness())){
            business.setText(Constant.getbusiness(item.getBusiness()));
        }


        payablePrice.setText(CheckUtils.isEmptyNumber(item.getPayablePrice()));
        modifyPrice.setText(CheckUtils.isEmptyNumber(item.getModifyPrice()));




        View.OnClickListener  OnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WaitingOrderBean.ListBean items = mDataList.get(position);
//                if (v.getId()==R.id.takePhone_layout) {
//                    if (!CheckUtils.isEmpty(items.getTakePhone())) {
//                        ActivityUtils.callActivity(mContext, items.getTakePhone());
//                    }
//                    return;
//
//                }
                if (mOnItemChildClickListener!=null){

                    mOnItemChildClickListener.onChildItemClick(v.getId(), position,items);
                }

            }
        };
        recordBtn.setOnClickListener(OnClickListener);
      // takePhoneLayout.setOnClickListener(OnClickListener);
        priceBtn.setOnClickListener(OnClickListener);
    }


}
